#include <iostream>
using namespace std;
/*头文件*/
#include <fstream>
#include <stdio.h>
#include <iomanip>
int main()
{
#if 0
    int num = 100;
    printf("num:%d\n", num);
    printf("num:%12d\n", num);
    printf("num:%-12d\n", num);
    printf("num:123456789\n");
    cout << "num:" << setw(12) << 777 << endl;
#endif
    const char *name = "./test.txt";
#if 0
    /*打开文件：使用构造函数的方式打开文件*/
    ofstream ofs(name);
#else

    ofstream ofs;
    /*out:写方式
    app:追加方式
    默认是out和trunc：覆盖
    */
    ofs.open(name, ios::out | ios::app);
#endif
    /*判断文件是否打开成功*/
    if (ofs.is_open())
    {
        cout << "open success" << endl;
    }

    /*写数据到文件*/
    ofs << "hello world\n";
    ofs.close();
    return 0;
}